package com.yuxi.common;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @author sunke
 * @Date 2019-10-08 21:28
 * @description
 */
@Component
public class SkRestTemplate extends RestTemplate {


    public <T> T getForObject(URI url, Class<T> responseType, HttpHeaders headers) throws RestClientException {
        if (headers == null) {
            return getForObject(url, responseType);
        }
        ResponseEntity<T> response = exchange(
                url,
                HttpMethod.GET,
                new HttpEntity<String>(headers),
                responseType);
        return response.getBody();


    }

    /**
     * Create a new instance of the {@link RestTemplate} using default settings.
     * Default {@link HttpMessageConverter}s are initialized.
     */

}
